package com.cnjson.sensor.controller;


import com.cnjson.sensor.nio.SocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.nio.channels.SocketChannel;
import java.util.concurrent.atomic.AtomicBoolean;

@RestController
    @RequestMapping("/controlEquipment")
public class ControlWaterQualitySensor {

    private static final Logger logger = LoggerFactory.getLogger(ControlWaterQualitySensor.class);

    @Autowired
    private SocketServer socketServer;


    @RequestMapping(method = RequestMethod.GET,value = "/run")
    public String runEquipment(String electricSignal,String remote,String equipmentNum) {


//        String electricSignal="0x81";
//        String remote="/39.144.18.93:56936";
//        int equipmentNum=20476;

        try {
            int num = Integer.valueOf(equipmentNum);

            if(socketServer.controllEquipment(electricSignal,remote,num))
                return "ok";
        }catch (Exception e){
            System.out.println("传入参数equipmentNum不能转化为int");
        }


        return "error";
    }


    @RequestMapping(method = RequestMethod.GET,value = "/shutdown")
    public String shutdownEquipment() {

        return "ok";
    }
}
